package com.hsy.bibc.modules.common;

import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hsy.bibc.R;
import com.hsy.bibc.modules.main.MainActivity;
import com.hsy.bibc.modules.order.OrderActivity;

public class CommitOkActivity extends CommonBaseActivityWithSimpleActionBar implements View.OnClickListener {

    protected TextView continueToValidate;
    protected TextView viewMyOrder;
    protected TextView msg;
    protected TextView orderSn;

    private String confirmType = "-1";

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK) {
            startActivityWithTaskCleared(MainActivity.class);
            return false;
        }
        return super.onKeyDown(keyCode, event);

    }

    @Override
    public boolean onActionBarLeftButtonClicked(ImageButton leftButton) {
        startActivityWithTaskCleared(MainActivity.class);
        return super.onActionBarLeftButtonClicked(leftButton);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_order_commit_ok);
        setTitle(R.string.txt_confirm_result);
        initView();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.continue_to_validate) {
//            switch (confirmType) {
//                case "1":
//                    break;
//                case "2":
//                    break;
//                case "3":
//                    break;
//
//            }
            startActivityWithTaskCleared(MainActivity.class);
        } else if (view.getId() == R.id.view_my_order) {
//            switch (confirmType) {
//                case "1":
//                    break;
//                case "2":
//                    break;
//                case "3":
//                    break;
//            }

            startActivity(OrderActivity.class, "CommitOk");
            finish();
        }
    }

    private void initView() {
        continueToValidate = (TextView) findViewById(R.id.continue_to_validate);
        continueToValidate.setOnClickListener(CommitOkActivity.this);
        viewMyOrder = (TextView) findViewById(R.id.view_my_order);
        viewMyOrder.setOnClickListener(CommitOkActivity.this);
        msg = (TextView) findViewById(R.id.msg);
        orderSn = (TextView) findViewById(R.id.order_sn);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (isEmpty(getActivityStartExtra())) {
            return;
        }
        confirmType = getActivityStartExtra()[0];
        switch (confirmType) {
            case "1":
                msg.setText("您已交易成功!积分将自动更新!");
                orderSn.setText(String.format("订单号:%s", getActivityStartExtra()[2]));
                continueToValidate.setText("继续验证");
                break;
            case "2":
                msg.setText("您已兑换成功!积分将自动更新!");
                orderSn.setText(String.format("订单号:%s", getActivityStartExtra()[2]));
                continueToValidate.setText("继续兑换");
                break;
            case "3":
                msg.setText("您已支付成功!积分将自动更新!");
                orderSn.setText(String.format("订单号:%s", getActivityStartExtra()[2]));
                continueToValidate.setText("继续验证");
                break;
        }
    }
}
